package test;

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class NGuessNumber {
    public static int[] generateAnswer()
    {
        int[] answer = new int[4];
        for (int i = 0; i < answer.length; i++)
        {
            answer[i] = -1;
        }
        int index = 0;
        while(index < answer.length)
        { Random rd = new Random();
            int num = rd.nextInt(10);
            if(judge(answer, num))
            {
                answer[index++]=num;
            }
        }
        return answer;
    }
    public static boolean judge(int[] arr, int num)
    {
        for (int i = 0; i < arr.length; i++)
        {
            if(arr[i] == num)
            {
                return false;
            }
        }
        return true;
    }
    public static int[] getPlayerInput()
    {
        int[] guess = new int[4];

        Scanner sc = new Scanner(System.in);

        for (int i = 0; i < 4; i++)
        {
            int temp = sc.nextInt();
            if (temp >= 0 && temp <= 9)
            {
                guess[i] = temp;
            }
        }
        System.out.println(Arrays.toString(guess));
        return guess;
    }
    public static int[] compareGuessAnswer(int[] answer, int[] guess)
    {
        int[] arr_AB = new int[2];

        int A = 0;
        int B = 0;

        for (int i = 0; i < 4; i++)
        {
            if (guess[i] == answer[i])
            {
                A++;
            }
        }

        for (int i = 0; i < 4; i++)
        {
            for (int j = 0; j < 4; j++)
            {
                if (guess[i] == answer[j])
                {
                    B++;
                }
            }
        }


        arr_AB[0] = A;
        arr_AB[1] = B;

        System.out.println("A = " + arr_AB[0] + ", B = " + arr_AB[1]);

        return arr_AB;
    }
}
